function findNearest(array, time) {
    var left = 0;
    var right = array.length - 1;
    if (array == null){
        return 0;
    }
    while (left <= right) {
        var mid = Math.floor((left + right) / 2);
        if (array[mid].startTime === time) {
            return mid;
        } else if (array[mid].startTime < time) {
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }
    // 如果给定时间小于数组的第一个元素，则返回 0
    if (right < 0) {
        return 0;
    }
    // 如果给定时间大于数组的最后一个元素，则返回最后一个索引
    if (left >= array.length) {
        return array.length - 1;
    }
    return left - 1;
}
const regex1 = /\[(\d{2}):(\d{2})\.(\d{2})\](.+?)(?=\[|$)/g;
const regex2 = /(.+?)(?=\[|$)\[(\d{2}):(\d{2})\.(\d{2})\]/g;
const pText1 = /\[(\d{2}):(\d{2})\.(\d{2})\]/g;
function lry2json(text) {
// 将每一行转为 JSON 对象
    const jsonArr = [];

    let split = text.split('\n');
    for (let i = 0; i < split.length; i++) {
        const line = split[i];
        try {
            const pText = line.replaceAll(pText1, "");
            let matchAll = Array.from(line.matchAll(regex1));
            let matchAll1 = Array.from(line.matchAll(regex2));
            let spanArr = []
            for (let j = 0; j < matchAll.length; j++) {
                console.log(matchAll[j])
                console.log(matchAll1[j])
                const startTime = parseFloat(matchAll[j][1]) * 60 + parseFloat(matchAll[j][2]) + parseFloat(matchAll[j][3]) / 100;
                const endTime = parseFloat(matchAll1[j][2]) * 60 + parseFloat(matchAll1[j][3]) + parseFloat(matchAll1[j][4]) / 100;
                let playTime = (endTime - startTime) * 1000
                let span1= {
                    text: matchAll[j][4],
                    wait: 0,
                    playTime: Math.round(playTime),
                    startTime: startTime.toFixed(2),
                };
                spanArr.push(span1)
            }
            jsonArr.push({
                pText: pText,
                startTime: spanArr[0].startTime,
                pSpan: spanArr,
            });
        }catch (e){ console.log(e);
        }
    }

    return jsonArr;
}
